{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #First Letter to Appear Twice"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #hash-table #string #counting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #哈希表 #字符串 #计数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: repeatedCharacter"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #第一个出现两次的字母"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个由小写英文字母组成的字符串 <code>s</code> ，请你找出并返回第一个出现 <strong>两次</strong> 的字母。</p>\n",
    "\n",
    "<p><strong>注意：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li>如果 <code>a</code> 的 <strong>第二次</strong> 出现比 <code>b</code> 的 <strong>第二次</strong> 出现在字符串中的位置更靠前，则认为字母 <code>a</code> 在字母 <code>b</code> 之前出现两次。</li>\n",
    "\t<li><code>s</code> 包含至少一个出现两次的字母。</li>\n",
    "</ul>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>s = \"abccbaacz\"\n",
    "<strong>输出：</strong>\"c\"\n",
    "<strong>解释：</strong>\n",
    "字母 'a' 在下标 0 、5 和 6 处出现。\n",
    "字母 'b' 在下标 1 和 4 处出现。\n",
    "字母 'c' 在下标 2 、3 和 7 处出现。\n",
    "字母 'z' 在下标 8 处出现。\n",
    "字母 'c' 是第一个出现两次的字母，因为在所有字母中，'c' 第二次出现的下标是最小的。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>s = \"abcdd\"\n",
    "<strong>输出：</strong>\"d\"\n",
    "<strong>解释：</strong>\n",
    "只有字母 'd' 出现两次，所以返回 'd' 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>2 &lt;= s.length &lt;= 100</code></li>\n",
    "\t<li><code>s</code> 由小写英文字母组成</li>\n",
    "\t<li><code>s</code> 包含至少一个重复字母</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [first-letter-to-appear-twice](https://leetcode.cn/problems/first-letter-to-appear-twice/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [first-letter-to-appear-twice](https://leetcode.cn/problems/first-letter-to-appear-twice/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"abccbaacz\"', '\"abcdd\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        lst = set()\n",
    "        for c in s:\n",
    "            if c in lst:\n",
    "                return c\n",
    "            else:\n",
    "                lst.add(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        dict_s = dict()\n",
    "        for str0 in s:\n",
    "            if str0 not in dict_s:\n",
    "                dict_s[str0] = 1\n",
    "            else:\n",
    "                return str0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        ans = set()\n",
    "        for num in s:\n",
    "            if num not in ans:\n",
    "                ans.add(num)\n",
    "            else:\n",
    "                return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        se = set()\n",
    "        for c in s:\n",
    "            if c in se:\n",
    "                return c\n",
    "            se.add(c)\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        exist={}\n",
    "        for c in s:\n",
    "            if exist.get(c):\n",
    "                return c\n",
    "            exist[c]=1\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        s_list = list(s)\n",
    "        length = len(s_list)\n",
    "        #暴力查找\n",
    "        # #先查找是否有相邻的\n",
    "        # for i in range(length-1):\n",
    "        #     if s_list[i+1] == s_list[i]:\n",
    "        #         return s_list[i]\n",
    "        # for i in range(length):\n",
    "        #     tmp = s_list[i]\n",
    "        #     for j in range(i+1,length):\n",
    "        #         if s_list[j] == tmp:\n",
    "        #             return tmp\n",
    "        # return -1\n",
    "        inde = []\n",
    "        compare_list = []\n",
    "        #先找出独一无二的字符\n",
    "        s_unique = set(s_list)\n",
    "        s_unique = list(s_unique)\n",
    "        inde = [[] for i in range(len(s_unique))]\n",
    "        for i in range(len(s_unique)):\n",
    "            tmp = s_unique[i]\n",
    "            for j in range(length):\n",
    "                if s_list[j] == tmp:\n",
    "                    inde[i].append(j)\n",
    "            if len(inde[i])>=2:\n",
    "                compare_list.append(inde[i][1])\n",
    "        minimum = min(compare_list)\n",
    "        # min_index = compare_list.index(min(compare_list))\n",
    "        return s_list[minimum]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        map={}\n",
    "        for i in range(0,len(s)):\n",
    "            map[s[i]]=map.get(s[i],0)+1\n",
    "            if map[s[i]]==2:\n",
    "                return s[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        checklist = {}\n",
    "\n",
    "        for i in s:\n",
    "            if i not in checklist.keys():\n",
    "                checklist[i] = 1\n",
    "            else:\n",
    "                checklist[i] += 1\n",
    "\n",
    "            if 2 in checklist.values():\n",
    "                return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        t = set()\n",
    "        for i in s:\n",
    "            if i not in t:\n",
    "                t.add(i)\n",
    "            else:\n",
    "                return i\n",
    "        return -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        letters = []\n",
    "        for letter in s:\n",
    "            if letter in letters:\n",
    "                return letter\n",
    "            else:\n",
    "                letters.append(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch \n",
    "            seen.add(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        n = len(s)\n",
    "        sign = []\n",
    "        for i in range(n - 1):\n",
    "            sign.append(s[i])\n",
    "            if s[i + 1] in sign:\n",
    "                ch = s[i + 1]\n",
    "                break\n",
    "        return ch\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        a = set()\n",
    "        for str in s:\n",
    "            if str in a:\n",
    "                return str\n",
    "            else:\n",
    "                a.add(str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        mask = 0\n",
    "        for x in s:\n",
    "            t = ord(x) - ord(\"a\")\n",
    "            if mask & (1 << t):\n",
    "                return x\n",
    "            mask |= 1 << t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        has = {}\n",
    "\n",
    "        for a in s:\n",
    "            if has.get(a):\n",
    "                return a\n",
    "            has[a] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        stack = []\n",
    "        for i in s:\n",
    "            if i in stack:\n",
    "                return i \n",
    "            else:\n",
    "                stack.append(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        l=''\n",
    "        for i in s:\n",
    "            if i in l:\n",
    "                return i\n",
    "            l+=i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        dic = {}\n",
    "        for i in s:\n",
    "            if i not in dic:\n",
    "                dic[i] = 1\n",
    "            else:\n",
    "                return i\n",
    "                break\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        hashmap = {}\n",
    "        for c in s:\n",
    "            hashmap[c] = hashmap.get(c , 0) + 1\n",
    "            if hashmap[c] == 2:\n",
    "                return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        uniq = set()\n",
    "        for c in s:\n",
    "            if c in uniq:\n",
    "                return c\n",
    "            uniq.add(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        s_l = list(s)\n",
    "\n",
    "        ans = []\n",
    "        for i in range(0, len(s_l)):\n",
    "            if s_l[i] not in ans:\n",
    "                ans.append(s_l[i])\n",
    "            else:\n",
    "                return s_l[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        s_2 = \"\"\n",
    "        for ch in s:\n",
    "            if ch in s_2:\n",
    "                return ch\n",
    "            else:\n",
    "                s_2 += ch\n",
    "\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "    \n",
    "        for i in s:\n",
    "            if i not in seen:\n",
    "                seen.add(i)\n",
    "            else:\n",
    "                return i\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        dd={}\n",
    "        for i in s:\n",
    "            dd[i] = dd.get(i,0)+1\n",
    "            if dd[i]==2:\n",
    "                return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        str1 = []\n",
    "        for i in s:\n",
    "            for j in str1:\n",
    "                if i == j:\n",
    "                    return i\n",
    "            str1.append(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        l = []\n",
    "        for x in s:\n",
    "            if x not in l:\n",
    "                l.append(x)\n",
    "            else:\n",
    "                return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        info = defaultdict(int)\n",
    "        for i in s:\n",
    "            info[i] += 1\n",
    "            c = max(info.items(),key = lambda x : x[1])\n",
    "            if c[1] == 2:\n",
    "                return c[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        dict = defaultdict(int)\n",
    "        for i in s:\n",
    "            dict[i] += 1\n",
    "            if dict[i] == 2:\n",
    "                return i\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        dic = {}\n",
    "        for c in s:\n",
    "            if c not in dic:\n",
    "                dic[c] = 1\n",
    "            else:\n",
    "                dic[c] += 1\n",
    "                if dic[c]==2:return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        times = [0]*26\n",
    "        for c in s:\n",
    "            num = ord(c)\n",
    "            if times[num-97] == 0:\n",
    "                times[num-97] +=1\n",
    "            else:\n",
    "                return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def repeatedCharacter(self, s: str) -> str:\n",
    "#         times = [0]*26\n",
    "#         for c in s:\n",
    "#             num = ord(c)\n",
    "#             if times[num-97] == 0:\n",
    "#                 times[num-97] +=1\n",
    "#             else:\n",
    "#                 return c\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        # 我们对字符串 sss 进行一次遍历。当遍历到字母 ccc 时，如果哈希表中包含 ccc，我们返回 ccc 作为答案即可；否则，我们将 ccc 加入哈希表。\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        temp = {}\n",
    "        for char in s:\n",
    "            if char not in temp.keys():\n",
    "                temp[char] = 1\n",
    "            else:\n",
    "                return char"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        hash_s = set()\n",
    "        for i in s:\n",
    "            if i not in hash_s:\n",
    "                hash_s.add(i)\n",
    "            else:\n",
    "                return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        st = set()\n",
    "        for c in s :\n",
    "            if c in st:return c\n",
    "            st. add(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        dic={}\n",
    "        for ch in s:\n",
    "            if ch not in dic :\n",
    "                dic[ch]=1\n",
    "            else:\n",
    "                dic[ch]+=1\n",
    "            if dic[ch]==2:\n",
    "                return ch\n",
    "                break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        t='!'\n",
    "        for i in s:\n",
    "            if i not in t:\n",
    "                t+=i\n",
    "            else:\n",
    "                return i\n",
    "                break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        t = set()\n",
    "        for i in s:\n",
    "            if i not in t:\n",
    "                t.add(i)\n",
    "            else:\n",
    "                return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        has = {}\n",
    "        for a in s:\n",
    "            if has.get(a):\n",
    "                return a\n",
    "            has[a] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        lst=[]\n",
    "        for i in s:\n",
    "            if i not in lst:\n",
    "                lst.append(i)\n",
    "            else:\n",
    "                return(i)\n",
    "                break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        list1=[]\n",
    "        for i in s:\n",
    "            if i not in list1:\n",
    "                list1.append(i)\n",
    "            else:\n",
    "                return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        d = {}\n",
    "        for i in s:\n",
    "            if not d.get(i, False):\n",
    "                d[i] = 1\n",
    "            else:\n",
    "                return i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        dic={}\n",
    "        for i in s:\n",
    "            if i not in dic:\n",
    "                dic[i]=1\n",
    "            else:\n",
    "                dic[i]+=1\n",
    "            if dic[i]==2:\n",
    "                break\n",
    "        return i\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        res = list()\n",
    "        for c in s:\n",
    "            if c not in res:\n",
    "                res.append(c)\n",
    "            else:\n",
    "                return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        has = {}\n",
    "        for a in s:\n",
    "            if has.get(a):\n",
    "                return a\n",
    "            has[a] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        has={}\n",
    "        for a in s:\n",
    "            if has.get(a):\n",
    "                return a\n",
    "            has[a]=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        for i,c in enumerate(s):\n",
    "            if c in s[:i]:return c\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        se = set()\n",
    "        for c in s:\n",
    "            if c in se:\n",
    "                return c\n",
    "            se.add(c)\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        mhash = 0\n",
    "        for ch in s:\n",
    "            x = ord(ch)-ord('a')\n",
    "            if mhash&(1<<x):\n",
    "                return ch\n",
    "            else:\n",
    "                mhash |=(1<<x)\n",
    "\n",
    "        # mset = set()\n",
    "        # for ch in s:\n",
    "        #     if ch in mset:\n",
    "        #         return ch\n",
    "        #     else:\n",
    "        #         mset.add(ch)\n",
    "\n",
    "        # mdic = {}\n",
    "        # for ch in s:\n",
    "        #     if mdic.get(ch):\n",
    "        #         return ch\n",
    "        #     else:\n",
    "        #         mdic[ch]=1\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        n = len(s)\n",
    "        m = []\n",
    "        for i in range(n-1):\n",
    "            for j in range(i+1,n):\n",
    "                if s[i] == s[j]:\n",
    "                    m.append(j)\n",
    "        return s[min(m)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        memo = set()\n",
    "        for x in s:\n",
    "            if x not in memo:\n",
    "                memo.add(x)\n",
    "            else:\n",
    "                return x\n",
    "        return ''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        seen = set()\n",
    "        for ch in s:\n",
    "            if ch in seen:\n",
    "                return ch\n",
    "            seen.add(ch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        my_dict = {}\n",
    "        my_list = list(s)\n",
    "        for index, value in enumerate(my_list):\n",
    "            if my_list[index] not in my_dict:\n",
    "                my_dict[value] = index\n",
    "            else:\n",
    "                return my_list[index]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        lst = [0] * 26\n",
    "        for c in s:\n",
    "            n = ord(c) - 97\n",
    "            if lst[n] == 0:\n",
    "                lst[n] = 1\n",
    "            else:\n",
    "                return c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        count = set()\n",
    "\n",
    "        for c in s:\n",
    "            if c in count:\n",
    "                return c\n",
    "            count.add(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        res = set()\n",
    "        for i in s:\n",
    "            if i in res:\n",
    "                return i\n",
    "            else:\n",
    "                res.add(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        d = set()\n",
    "        for c in s:\n",
    "            if c in d:\n",
    "                return c\n",
    "            d.add(c)\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        ds = {}\n",
    "        for i in s:\n",
    "            ds[i] = ds.get(i,0)\n",
    "            ds[i] += 1\n",
    "            if ds[i] == 2:\n",
    "                return i "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        st=set()\n",
    "        for c in s:\n",
    "            if c in st:return c \n",
    "            st.add(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        gather = set()\n",
    "        for num in s :\n",
    "            if num in gather: return num\n",
    "            gather.add(num)\n",
    "    \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "        alpha_list = []\n",
    "        for c in s:\n",
    "            if c in alpha_list:\n",
    "                return c\n",
    "            alpha_list.append(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def repeatedCharacter(self, s: str) -> str:\n",
    "\n",
    "        count = defaultdict(int)\n",
    "        \n",
    "        for i, c in enumerate(s):\n",
    "            count[c] += 1\n",
    "            if count[c] == 2:\n",
    "                return c\n",
    "        "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
